<?php
namespace Index\Controller;
use Think\Controller;
class AskController extends CommonController {
	public function indexAction(){
		layout('layoutask');

       	$this->display();
    }

    public function howtoaskAction(){


       	$this->display();
    }

    public function saveAction()
    {

    	if(IS_POST){

            $title = I('post.title');
            $category = I('post.category');
            $editorValue = I('post.editorValue');
            $uid = $_SESSION['id'];
            $create_time = time();


            $sql = "insert into question (title,content,create_time,uid) value('{$title}','{$editorValue}','{$create_time}','{$uid}')";

            $res= M()->execute($sql);

            if($res){
                $qid = M()->getLastInsID();
                foreach ($category as $cid) {
                    $sql = "insert into category_question (cid,qid) value('{$cid}','{$qid}')";
                    $res =  M()->execute($sql);
                }

                $this->success('提问成功',U('Index/question/index',array('id'=>$qid)));


            }else{
                 $this->error('提问失败');
            }

            



    		// 把数据接收

    		// 插入数据库，返回问题ID

    		// 再根据ID循环插入多个分类

    		
    	}
    }


    public function ueditorAction(){
        $data = new \Org\Util\Ueditor();
        echo $data->output();
    }
}